#include <iostream>
using namespace std;

const int N = 1e5 + 10;
int n;
int prices[N];
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> prices[i];

    int ret = 0, prevMin = prices[0];
    for (int i = 1; i < n; i++)
    {
        ret = max(ret, prices[i] - prevMin);
        prevMin = min(prices[i], prevMin);
        if (ret < 0)
            ret = 0;
    }

    cout << ret << endl;
    return 0;
}